Regions Cut by Slashes
Try to solve the Regions Cut By Slashes problem.
We'll cover the following
Statement#
An grid is composed of , squares, where each square consists of a “/”, “\”, or a blank space. These characters divide the square into adjacent regions.
Given the grid represented as a string array, return the number of adjacent regions.
Note:
- Backslash characters are escaped, so “\” is represented as “\\”.
- A square in the grid will be referred to as a box.
Constraints:
- The grid consists of only the “/”, “\”, or " " characters.
- 1
grid.length30
The following illustration shows how the grid can be visualized:
1 of 16
2 of 16
3 of 16
4 of 16
5 of 16
6 of 16
7 of 16
8 of 16
9 of 16
10 of 16
11 of 16
12 of 16
13 of 16
14 of 16
15 of 16
16 of 16
Examples#
1 of 3
2 of 3
3 of 3
Understand the problem#
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Regions Cut By Slashes
What is the output if the following grid is given as input?
grid = [" /", “/ /”, "\\/ "]
1
2
3
4
Figure it out!#
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself#
Implement your solution in main.py in the following coding playground. You will need the provided supporting code to implement your solution.
Solution: Last Day Where You Can Still Cross
Solution: Regions Cut by Slashes